/**
  **************************************************************************
  * @file     at32f415_int.c
  * @brief    main interrupt service routines.
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

/* includes ------------------------------------------------------------------*/
#include "at32f415_board.h"
#include "at32f415_clock.h"
#include "at32f415_int.h"
#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"

/** @addtogroup AT32F415_periph_template
  * @{
  */

/** @addtogroup 415_LED_toggle
  * @{
  */

/**
  * @brief  this function handles nmi exception.
  * @param  none
  * @retval none
  */
void NMI_Handler(void)
{
}

/**
  * @brief  this function handles hard fault exception.
  * @param  none
  * @retval none
  */
void HardFault_Handler(void)
{
  /* go to infinite loop when hard fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles memory manage exception.
  * @param  none
  * @retval none
  */
void MemManage_Handler(void)
{
  /* go to infinite loop when memory manage exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles bus fault exception.
  * @param  none
  * @retval none
  */
void BusFault_Handler(void)
{
  /* go to infinite loop when bus fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles usage fault exception.
  * @param  none
  * @retval none
  */
void UsageFault_Handler(void)
{
  /* go to infinite loop when usage fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles svcall exception.
  * @param  none
  * @retval none
  */
void SVC_Handler(void)
{
}

/**
  * @brief  this function handles debug monitor exception.
  * @param  none
  * @retval none
  */
void DebugMon_Handler(void)
{
}

/**
  * @brief  this function handles pendsv_handler exception.
  * @param  none
  * @retval none
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  this function handles systick handler.
  * @param  none
  * @retval none
  */
void SysTick_Handler(void)
{
}

/**
  * @brief  this function handles timer1 overflow handler.
  * @param  none
  * @retval none
  */
void TMR1_OVF_TMR10_IRQHandler(void)
{
  if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) != RESET)
  {
    /* add user code... */
		static u16 tim = 0;
		static u8 test_tim = 0;
		static char test_flag = 1;
		
		if(test_flag){
			if(tim >= 2000){
				gpio_bits_reset(GPIOF,GPIO_PINS_6);
				gpio_bits_reset(GPIOB,GPIO_PINS_6);
//				gpio_bits_reset(GPIOB,GPIO_PINS_7);
			}
			else if(tim <= 2000){
				gpio_bits_set(GPIOF,GPIO_PINS_6);
				gpio_bits_set(GPIOB,GPIO_PINS_6);
//				gpio_bits_set(GPIOB,GPIO_PINS_7);
			}
		}
		
		if(tim >= 4000){
			tim = 0;
			test_tim++;
		}
		
		if(test_tim >= 50){
			test_flag = 0;
		}
		
		tim++;
		
		lv_tick_inc(1);
		
    tmr_flag_clear(TMR1, TMR_OVF_FLAG);
  }
}

///**
//  * @brief  usart1 interrupt handler.
//  * @param  none
//  * @retval none
//  */
//void USART1_IRQHandler(void)
//{
//}

///**
//  * @brief  usart2 interrupt handler
//  * @param  none
//  * @retval none
//  */
//void USART2_IRQHandler(void)
//{
//}

///**
//  * @brief  can1 interrupt handler
//  * @param  none
//  * @retval none
//  */
//void CAN1_RX0_IRQHandler(void)
//{

//}
